<template>
  <div id="login-box">
    <div class="formContainer">
      <div class="form">
        <div class="item">
          <i class="fa fa-user" aria-hidden="true"></i>
          <input type="text" placeholder="Username" autocomplete="off" />
        </div>
        <div class="item">
          <i class="fa fa-key" aria-hidden="true"></i>
          <input type="password" placeholder="Password" autocomplete="off" />
        </div>
      </div>
      <button @click="login">登录</button>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
import { useRouter, useRoute } from "vue-router";
import router from "@/router/index";
import store from "@/store/index";

export default defineComponent({
  name: "Login",
  setup() {
    const roter = useRouter();
    const tt = useRoute();
    async function login() {
      store.commit("set_loading", true);
      timer();
    }
    async function timer() {
      setTimeout(async () => {
        let routes = await store.dispatch("generateRoutes", "editor", {
          root: true,
        });
        console.log("路由useRoute实例，添加路由之前", tt, router.getRoutes());
        console.log("await login routes1", routes);
        routes.forEach((item,index) => {
          console.log('循环', item,index)
          router.addRoute(item);
        });
        console.log("路由useRoute实例，添加路由之后", tt, router.getRoutes());
        store.commit('set_router',router.getRoutes())
        store.commit("login", "232342342342");
        roter.push("/home");
        store.commit("set_loading", false);
      }, 1000);
    }
    return {
      login,
      timer,
    };
  },
});
</script>

<style lang="scss">
#login-box {
  height: 100vh;
  text-align: center;
  background: {
    image: url(../../assets/loginBg2.jpg);
    attachment: fixed;
    size: cover;
  }
  display: flex;
  align-items: center;
  justify-content: center;
}
.formContainer {
  background: inherit;
  width: 400px;
  height: 300px;
  border-radius: 20px;
  position: relative;
  overflow: hidden; //adding overflow hidden
  z-index: 1;
  &::before {
    z-index: -1;
    content: "";
    background: inherit;
    position: absolute;
    left: -25px; //giving minus -25px left position
    right: 0;
    top: -25px; //giving minus -25px top position
    bottom: 0;
    box-shadow: inset 0 0 0 200px rgba(255, 255, 255, 0.3);
    filter: blur(20px);
    background-size: cover;
    background-attachment: fixed;
  }
  .form {

    z-index: 666;
    margin-top: 70px;
  }
}
#login-box h1 {
  color: black;
}

#login-box .form i {
  font-size: 18px;
  color: #ffffff;
}

#login-box .form .item {
  margin-top: 30px;
}

#login-box .form .item input {
  width: 220px;
  font-size: 18px;
  border: 0;
  border-bottom: 2px solid #ffffff;
  padding: 5px 10px;
  // background: #ffffff00;
  background-color: transparent;
  color: #ffffff;
  outline: none;
  transition: all 0.3s;
  &:hover {
    border-color: #d16ba5;
  }
  &:focus {
    border-color: #d16ba5;
    width: 280px;
  }
  &:-webkit-autofill,
  &:-webkit-autofill:hover,
  &:-webkit-autofill:focus,
  &:-webkit-autofill:active {
    transition: all 0.3s;
  }
  &:-webkit-autofll {
    border: none;
    background: none;
  }
}

#login-box button {
  margin-top: 30px;
  width: 220px;
  height: 40px;
  font: {
    size: 20px;
    weight: 700;
  }
  border: none;
  outline: none;
  background-image: linear-gradient(
    to right,
    #f0c8d9,
    #f0adce,
    #ed91c4,
    #e875bd,
    #e155b7
  );
  border-radius: 15px;
  transition: all 0.3s;
  color: white;
  cursor: pointer;
  &:hover {
    transform: scale(1.2);
    box-shadow: 3px 3px 10px 3px rgba($color: #000000, $alpha: 0.3);
  }
}
</style>